

package com.example.demo.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Data;

@JsonInclude(Include.NON_NULL)
@Data
public class RestResponse<T> {

	private int code;
	
	private String message;
	
	private T data;

	public static <T> RestResponse<T> success() {
		return new RestResponse<T>();
	}

	public static <T> RestResponse<T> success(T result) {
		RestResponse<T> response = new RestResponse<T>();
		response.setData(result);
		return response;
	}

	public static <T> RestResponse<T> validfail(String msg) {
		RestResponse<T> response = new RestResponse<T>();
		response.setCode(-2);
		response.setMessage(msg);
		return response;
	}

	public RestResponse() {
		this(20000, "");
	}

	public RestResponse(int code, String msg) {
		this.code = code;
		this.message = msg;
	}


	@JsonIgnore
	public Boolean isSuccessful() {
		return this.code == 20000;
	}

}
